package com.yan.jdbcdemo;

import com.yan.utils.JDBCUtil;

import java.sql.*;
import java.util.Scanner;

/**
 * @author taoge
 * @Date 2024/8/23 9:36
 * @Description
 */
public class JDBCDemo1 {
    public static void main(String[] args) throws SQLException {
        Scanner input = new Scanner(System.in);
        System.out.println("输入用户名");
        String userName = input.nextLine();
        System.out.println("输入密码");
        String passWord = input.nextLine();
        // 建立连接
        Connection connection = JDBCUtil.connection();

        // 编写sql语句
        String sql = "select * from user where userName  = ? and passWord = ?";

        // 创立传输对象
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setObject(1 ,userName);
        preparedStatement.setObject(2,passWord);
        // 传输sql语句
        ResultSet rs = preparedStatement.executeQuery();

        if(rs.next()){
            System.out.println("登录成功! 欢迎" + userName);
        }else{
            System.out.println("登录失败");
        }


        // 关闭资源
        JDBCUtil.Close(preparedStatement ,connection);
    }
}
